package physics.collision;

import java.awt.geom.Point2D;
import model.objects.GameObject;
import model.objects.Level;


/**
 * Defines the collision strategy for enemies. These call a levelLost if
 * impacted from the side or bottom.
 * 
 * @author geo4
 * 
 */
public class EnemyCollisionStrategy implements CollisionStrategy {

    /**
     * Y-component of the GameObject's velocity after it has impacted the top of
     * an enemy and has bounced off.
     */
    private static final double BOUNCE_SPEED = -2;

    @Override
    public void collisionAction (Level level, CollisionEvent collisionEvent) {
        if (collisionEvent.collided(CollisionEvent.Direction.TOP)) {
            // TODO mark this object for deletion
            Point2D impactedVelocity =
                    ((GameObject) collisionEvent.getImpactedObject()).getVelocity();
            impactedVelocity.setLocation(impactedVelocity.getX(), BOUNCE_SPEED);
        }
        else if (collisionEvent.collided(CollisionEvent.Direction.TOP) ||
                 collisionEvent.collided(CollisionEvent.Direction.SIDE)) {
            // TODO major bug. levelLost called whenever the enemies touches
            // anything, hero or not.
            level.setLevelLost(true, "Hit an enemy");
        }

    }
}
